import { area } from './api';

export const formItems = [
  // {
  //   label: '企业ID',
  //   name: 'username',
  //   value: 'mingcheng',
  //   type: 'input',
  // },
  {
    label: '企业名称',
    name: 'name',
    type: 'input',
  },
  {
    label: '手机号码',
    name: 'mobile',
    type: 'input',
  },
  {
    label: '账号密码',
    name: 'password',
    type: 'input',
    required: true,
  },
  {
    label: '企业地址',
    name: 'area',
    type: 'cascader',
    asyncOptions: {
      api: area,
      handleData(data) {
        let handleTree = (arr) => {
          return arr.map((item) => {
            item.label = item.name;
            item.value = item.id;
            if (item.children && item.children.length > 0) {
              handleTree(item.children);
            }
            return item;
          });
        };
        return handleTree(data);
      },
    },
  },
  {
    label: '详细地址',
    name: 'address',
    type: 'input',
    required: true,
    // hidden: (fromState, formItems, m) => {
    //   return fromState.mobile == 1;
    // },
  },
  {
    label: '法人姓名',
    name: 'username',
    type: 'input',
    required: true,
  },
  {
    label: '法人身份证号',
    name: 'id_card',
    type: 'input',
  },
  {
    label: '营业执照',
    name: 'business_license',
    slot: 'business_license',
  },
];

export const formItems2Rules = {
  name: [
    {
      required: true,
      message: '请填写企业名称',
    },
    {
      max: 20,
      message: '最多20个字符',
    },
  ],
  mobile: [
    {
      required: true,
      message: '请填写手机号码',
      pattern: /1\d{10}/,
    },
  ],
  area: [
    {
      type: 'array',
      required: true,
      message: '请选择区域',
    },
  ],
  id_card: [
    {
      required: true,
      message: '请输入法人身份证号',
      pattern:
        /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
      trigger: 'change',
    },
  ],
  business_license: [
    {
      type: 'array',
      required: true,
      message: '请上传营业执照',
      trigger: 'blur',
    },
  ],
};
